package io.github.xxyopen.novel.generator;

import cn.hutool.core.io.file.FileReader;
import io.github.xxyopen.novel.service.ParticipleService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class DataLoader {
    @Autowired
    ParticipleService participleService;

    @Test
    public void loadParticiple(){
        String filePath = "/Users/mac/code/novel/doc/record/分词简体.txt";
        FileReader fileReader = new FileReader(filePath);
        List<String> words = fileReader.readLines();

        List<String> bathWords = new ArrayList<>();
        for (int i=0;i<words.size();i++){
            String word = words.get(i);
            if (word.getBytes(StandardCharsets.UTF_8).length>50){
                continue;
            }
            bathWords.add(word);
            if (i%100==0){
                participleService.batchSaveParticiple(bathWords);
                bathWords.clear();
            }
        }
        if (bathWords.size()>0){
            participleService.batchSaveParticiple(bathWords);
        }
    }

    public static void main(String[] args) {
        Integer m = Integer.valueOf(111);
        Integer n = Integer.valueOf(111);
        System.out.println(m == n);

        m = new Integer(111);
        n = new Integer(111);
        System.out.println(m == n);

        Integer i = Integer.valueOf(222);
        Integer j = Integer.valueOf(222);
        System.out.println(i == j);

        i = new Integer(222);
        j = new Integer(222);
        System.out.println(i == j);
    }


}
